'use strict';

let redis = require('redis');
global.client = redis.createClient({
  db: 1,
  prefix: 'user_'
});
module.exports = function(req, res, next) {
  let key = req.headers['authorization'];
  if (!key) return next();
  client.get(key, (err, value) => {
    if (err) return next(err);

    if (!value) return next();
    req.user = JSON.parse(value);
    next();
  });
};
